<?php

namespace Addons\Slide;
use Common\Controller\Addon;

/**
 * 轮播图插件插件
 * @author 小星星
 */

    class SlideAddon extends Addon{

        public $info = array(
            'name'=>'Slide',
            'title'=>'轮播图插件',
            'description'=>'这是一个轮播图插件',
            'status'=>0,
            'author'=>'小星星',
            'version'=>'0.1'
        );

        public $admin_list = array(
            'model'=>'slide',		//要查的表
                            'fields'=>'*',			//要查的字段
                            'listKey'=>array( 		//这里定义的是除了id序号外的表格里字段显示的表头名
                            'status'=>'链接',
                             'name'=>'描述',
                            'img'=>'图片路径',
                             'edit'=>'操作'
                                )
        );

        public $custom_adminlist = 'adminlist.html';

        public function install(){
            $prefix = C("DB_PREFIX");
            D()->execute("DROP TABLE IF EXISTS `{$prefix}slide`");
            D()->execute("DROP TABLE IF EXISTS `{$prefix}slides`");
            D()->execute(<<<SQL
CREATE TABLE IF NOT EXISTS `{$prefix}slide` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `auto` VARCHAR(20) NOT NULL DEFAULT 'true',
  `random`  VARCHAR(20) NOT NULL DEFAULT 'true',
  `nav`  VARCHAR(20) NOT NULL DEFAULT 'true',
  `status` int(5) NOT NULL DEFAULT '0',
  `timeout` int(6) NOT NULL DEFAULT 4000,
  `name`  VARCHAR (30) NOT NULL,
  `maxwidth`  int(6) NOT NULL DEFAULT 250,
  `maxheight`  int(6) NOT NULL DEFAULT 180,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
SQL
            );
            D()->execute(<<<SQL

            CREATE TABLE IF NOT EXISTS `{$prefix}slides` (
            `id` int(11) NOT NULL AUTO_INCREMENT,
  `href` VARCHAR (120) NOT NULL DEFAULT '0',
  `info`  VARCHAR (100) NOT NULL,
  `pid`  int(2) NOT NULL,
  `img` VARCHAR (30) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
SQL
            );
            return true;
        }

        public function uninstall(){
            $prefix = C("DB_PREFIX");
            D()->execute("DROP TABLE IF EXISTS `{$prefix}slide`");
            D()->execute("DROP TABLE IF EXISTS `{$prefix}slides`");
            return true;
        }

        //实现的dislunbo钩子方法
        public function dislunbo($param){
            //echo "dd";die;
            $list = D('Addons://Slide/Slide')->linkList($param);
            //var_dump($list);die;
            if($list[0]['status']==0){
                return false;
            }
            $this->assign('list',$list);
            $this->display('dislunbo');
        }

    }